<div class="page-header">
	<ul id="table-tab" class="nav nav-tabs" role="tablist">
		<li role="presentation" class=""><a href="#group-tab"
			aria-controls="group-tab" role="tab" data-toggle="tab">用户组管理</a></li>
	</ul>
</div>

<div class="tab-content">
	<div id="group-tab" class="tab-pane active" role="tabpanel">
		<div class="row">
			<div class="col-md-3">
            	<div class="widget-box">
                    <div class="widget-body">
                        <div class="widget-main padding-8" style="overflow-x:auto;">
                            <ul id="treeorg" class="ztree"></ul>
                        </div>
                    </div>
                </div>
            </div>
			<!--搜索域-->
			<div class="col-md-9">
				<div class="search-area">
					<form id="table-group-search" class="form-inline">
						<input type="hidden" id="group-orgid" name="group.orgid" value="">
						<div class="form-group">
							<label for="group.name">用户组名称：</label> <input type="text"
								class="form-control input-sm" id="group-name" name="group.name"
								value="" placeholder="">
						</div>
						<div class="form-group">
							<label for="group.code">用户组编码：</label> <input type="text"
								class="form-control input-sm" id="group-code" name="group.code"
								value="" placeholder="">
						</div>
						<button id="btn-group-search" type="button"
							class="btn btn-info btn-sm no-border">
							<i class="ace-icon fa fa-search bigger-110"></i>查询
						</button>
						<div class="form-group pull-right">
							<span>查询方式：</span>
							<label class="radio-inline">
								<input type="radio" name="searchType" value="1" checked="checked" />精确
							</label>
							<label class="radio-inline">
								<input type="radio" name="searchType" value="0" />模糊
							</label>
						</div>
					</form>
				</div>
				<!-- 数据表格 -->
				<div id="table-group-toolbar">
					<div class="btn-group btn-group-sm">
						<!-- 
						<button id="viewGroup" class="btn btn-purple btn-sm no-border">
							<i class="ace-icon fa  fa-eye bigger-110 "></i>查看
						</button>
						<button id="addGroup" class="btn btn-info btn-sm no-border"
							onclick="goAddBefore('');">
							<i class="ace-icon fa fa-plus bigger-110"></i>新增
						</button>
						<button id="editGroup" class="btn btn-success btn-sm no-border"
							onclick="goUpdate('编辑用户组', 'system/admin/group/edit', 'table-group');">
							<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>编辑
						</button>
						<button id="delGroup" class="btn btn-danger btn-sm no-border"
							onclick="doDels('system/admin/group/deletes', 'table-group');">
							<i class="ace-icon fa fa-trash-o bigger-110"></i>删除
						</button>
						<button id="allocRole" class="btn btn-success btn-sm no-border"
							onclick="goAlloc('分配角色', 'system/admin/group/allocRole');">
							<i class="ace-icon fa fa-pencil-square-o bigger-110"></i>分配角色
						</button>
						 -->
						 <x:toolbar menuId="${menuId}" elemIds="addGroup,editGroup,delGroup,allocRole">
	                  	 </x:toolbar>
					</div>
				</div>
				<table id="table-group" data-toolbar="#table-group-toolbar"
					data-sort-name="uuid" data-sort-order="asc"
					data-show-columns="true" data-id-field="uuid">
					<thead>
						<tr>
							<th data-field="state" data-checkbox="true"></th>
							<th data-width="140" data-field="name" data-align="left"
								data-sortable="false">用户组名称</th>
							<th data-field="code" data-align="left" data-sortable="true">用户组编码</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	$(function() {
		$.fn.zTree.init($("#treeorg"), {
			async: {
				enable: true,
				url:"system/admin/org/tree",
				autoParam:["uuid", "alevel"],
				dataFilter: ajaxFilter
			},
			callback:{
				onClick:treeOnClick
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "uuid",
					pIdKey: "parentid",
					rootPId: null
				}
			},
			check: {
				enable: false,
				autoCheckTrigger: false,
				chkboxType: { "Y" : "p", "N" : "p" }
			}
		});

		function ajaxFilter(treeId, pNode, respData){
			var nodes = null;
			if(respData.status == 'OK'){
				nodes = respData.rows;
			}
			if(nodes != null && nodes.length > 0){
				$('#group-orgid').val(nodes[0].uuid);
				$('#addgroup').attr("onclick", "goAddBefore('" + nodes[0].uuid + "');");
				initTableList('table-group', 'system/admin/group/dataGrid', 'table-group-search', 'btn-group-search');
			}
			return nodes;
		}
		
		function treeOnClick(event, treeId, treeNode){
			if(treeNode.uuid == null){
				$('#group-orgid').val("");
			} else {
				$('#group-orgid').val(treeNode.uuid);
			}
			$('#table-group').bootstrapTable('selectPage', 1);
			//刷新完毕还原
			//$('#org-level').val("");
			//$('#org-parentid').val("");
			//改变add 参数
			var uuid = '';
			if(treeNode.uuid !== null && treeNode.uuid != undefined){
				uuid = treeNode.uuid;
			}
			$('#addGroup').attr("onclick", "goAddBefore('" + uuid + "');");
		};
		
	});

	function goAddBefore(uuid){
		if(uuid == '' || uuid == 'undefined'){
			TipMsg.error("请选择一个有效的机构进行新增操作", 0);
		} else {
			var url = 'system/admin/group/add?orgid=' + uuid;
			goAdd('新增用户组', url, 'table-group');
		}
	}
	
	function goAlloc(title, url) {
		var selections = $('#table-group').bootstrapTable("getSelections");
		if (selections !== undefined && selections !== null) {
			if (selections.length === 1) {
				var id = selections[0].uuid;
				url = url + '?groupId=' + id;
				loadModal(url, function(data, status) {
					if (status === "success") {
						changeModalTitle(title);
						showModal();
					} else if (status === "timeout") {
						TipMsg.error("请求超时，请重试!!!", 0);
					}
				});
			} else {
				TipMsg.error("请选择一个用户组.", 0);
			}
		} else {
			TipMsg.error("没有可分配的用户组.", 0);
		}
	};
</script>
